package com.bjtu.literatureclient.dao.team;

import com.bjtu.literatureclient.domain.base.BaseModel;
import com.bjtu.literatureclient.domain.team.Team;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface ITeamDao {// dao 层定义方法接口，然后在service层和serviceimpl层实现接口方法，从而达到操作数据库的目的。
	/*
	 * @Select("<script>SELECT  * FROM teamtable WHERE 1=1\n" +
	 * "<if test=\"teamNo!=null and teamNo!=''\">\n" + "AND TeamNo=#{teamNo}\n" +
	 * "</if>\n" + "<if test=\"userName!=null and userName!=''\">\n" +
	 * "AND UserName=#{userName}\n" + "</if>\n" +
	 * "<if test=\"password!=null and password!=''\">\n" +
	 * "AND Password=#{password}\n" + "</if>\n" +
	 * "<if test=\"teamName!=null and teamName!=''\">\n" +
	 * "AND TeamName=#{teamName}\n" + "</if>\n" +
	 * "<if test=\"category!=null and category!=''\">\n" +
	 * "AND Category=#{category}\n" + "</if>\n" +
	 * "<if test=\"discipline!=null and discipline!=''\">\n" +
	 * " AND Discipline=#{discipline}\n" + "</if>" +
	 * "<if test=\"currentNum!=null and currentNum!=''\">\n" +
	 * "AND CurrentNum=#{currentNum}\n" + "</if>\n" +
	 * "<if test=\"maxNum!=null and maxNum!=''\">\n" + "AND MaxNum=#{maxNum}\n" +
	 * "</if>\n" + "<if test=\"userEmail!=null and userEmail!=''\">\n" +
	 * "AND UserEmail=#{userEmail}\n" + "</if>\n" +
	 * "<if test=\"teamEmail!=null and teamEmail!=''\">\n" +
	 * "AND TeamEmail=#{teamEmail}\n" + "</if>\n" +
	 * "<if test=\"userRole!=null and userRole!=''\">\n" +
	 * "AND UserRole=#{userRole}\n" + "</if>\n" +
	 * "<if test=\"date!=null and date!=''\">\n" + "AND Date=#{date}\n" + "</if>\n"
	 * + "<if test=\"note!=null and note!=''\">\n" + "AND Note=#{note}\n" +
	 * "</if>\n" + "<if test=\"ifuse!=null and ifuse!=''\">\n" +
	 * "AND IfUse=#{ifuse}\n" + "</if>\n" +
	 * "<if test=\"dateTime!=null and dateTime!=''\">\n" +
	 * "AND DateTime=#{dateTime}\n" + "</if>\n" + "</script>")
	 */
//	@Select("<script>SELECT  * FROM teamtable WHERE 1=1\n" +
//            "<if test=\"teamNo!=null and teamNo!=''\">\n" +
//            "AND TeamNo=#{teamNo}\n" +
//            "</if>\n" +
//            "<if test=\"userName!=null and userName!=''\">\n" +
//            "AND UserName=#{userName}\n" +
//            "</if>\n" +
//            "<if test=\"password!=null and password!=''\">\n" +
//            "AND Password=#{password}\n" +
//            "</if>\n" +
//            "<if test=\"teamName!=null and teamName!=''\">\n" +
//            "AND TeamName=#{teamName}\n" +
//            "</if>\n" +
//            "<if test=\"category!=null and category!=''\">\n" +
//            "AND Category=#{category}\n" +
//            "</if>\n" +
//            "<if test=\"discipline!=null and discipline!=''\">\n" +
//            " AND Discipline=#{discipline}\n" +
//            "</if>" +
//            "<if test=\"currentNum!=null and currentNum!=''\">\n" +
//            "AND CurrentNum=#{currentNum}\n" +
//            "</if>\n" +
//            "<if test=\"maxNum!=null and maxNum!=''\">\n" +
//            "AND MaxNum=#{maxNum}\n" +
//            "</if>\n" +
//            "<if test=\"userEmail!=null and userEmail!=''\">\n" +
//            "AND UserEmail=#{userEmail}\n" +
//            "</if>\n" +
//            "<if test=\"teamEmail!=null and teamEmail!=''\">\n" +
//            "AND TeamEmail=#{teamEmail}\n" +
//            "</if>\n" +
//            "<if test=\"userRole!=null and userRole!=''\">\n" +
//            "AND UserRole=#{userRole}\n" +
//            "</if>\n" +
//            "<if test=\"date!=null and date!=''\">\n" +
//            "AND Date=#{date}\n" +
//            "</if>\n" +
//            "<if test=\"note!=null and note!=''\">\n" +
//            "AND Note=#{note}\n" +
//            "</if>\n" +
//            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
//            "AND DateTime=#{dateTime}\n" +
//            "</if>\n" +
//            "</script>")
//    List<Team> query(BaseModel baseModel);

	@Select("<script>SELECT  * FROM teamtable WHERE 1=1\n" + "<if test=\"teamNo!=null and teamNo!=''\">\n"
			+ "AND TeamNo=#{teamNo}\n" + "</if>\n" + "<if test=\"userName!=null and userName!=''\">\n"
			+ "AND UserName=#{userName}\n" + "</if>\n" + "<if test=\"teamState!=null and teamState!=''\">\n"
			+ "AND TeamState=#{teamState}\n" + "</if>\n" + "<if test=\"teamName!=null and teamName!=''\">\n"
			+ "AND TeamName=#{teamName}\n" + "</if>\n" + "<if test=\"currentNum!=null and currentNum!=''\">\n"
			+ "AND CurrentNum=#{currentNum}\n" + "</if>\n" + "<if test=\"maxNum!=null and maxNum!=''\">\n"
			+ "AND MaxNum=#{maxNum}\n" + "</if>\n" + "<if test=\"userEmail!=null and userEmail!=''\">\n"
			+ "AND UserEmail=#{userEmail}\n" + "</if>\n" + "<if test=\"teamEmail!=null and teamEmail!=''\">\n"
			+ "AND TeamEmail=#{teamEmail}\n" + "</if>\n" + "<if test=\"note!=null and note!=''\">\n"
			+ "AND Note=#{note}\n" + "</if>\n" + "<if test=\"date!=null and date!=''\">\n"
			+ "AND Date=#{date}\n" + "</if>\n" + "<if test=\"note!=null and note!=''\">\n" + "AND Note=#{note}\n"
			+ "</if>\n" + "<if test=\"dateTime!=null and dateTime!=''\">\n" + "AND DateTime=#{dateTime}\n" + "</if>\n"
			+ "</script>")
	List<Team> query(Team team);

	@Select({ "select * from teamtable order by TeamNo DESC limit 0,1" })
	Team getMaxIdTeam();

	/*
	 * @Insert("<script>" +
	 * " INSERT INTO teamtable (TeamNo,UserName,Password, TeamName,Category,Discipline,"
	 * +
	 * " CurrentNum, MaxNum, UserEmail, TeamEmail, UserRole, Date, Note, DateTime, IfUse,State)"
	 * +
	 * " VALUES (#{teamNo},#{userName},#{password},#{teamName},#{category},#{discipline},"
	 * +
	 * " #{currentNum},#{maxNum},#{userEmail},#{teamEmail},#{userRole},#{date},#{note},#{dateTime},#{ifuse},#{state})"
	 * + "</script>")
	 */
	@Insert("<script>" + " INSERT INTO teamtable (TeamNo, UserName, TeamName,"
			+ " CurrentNum, MaxNum, UserEmail, Date, Note, DateTime, TeamState)"
			+ " VALUES (#{teamNo}, #{userName}, #{teamName},"
			+ " #{currentNum}, #{maxNum}, #{userEmail}, #{date}, #{note}, #{dateTime}, #{teamState})" + "</script>")
	int insert(Team team);

//	@Update("<script>" + " update teamtable set "
//			+ "UserName=#{userName}, TeamName=#{teamName}, CurrentNum=#{currentNum}, "
//			+ "MaxNum=#{maxNum}, UserEmail=#{userEmail}, TeamEmail=#{teamEmail}, "
//			+ "Date=#{date}, Note=#{note}, DateTime=#{dateTime}, TeamState=#{teamState} " + "where TeamNo=#{teamNo}"
//			+ "</script>")
//	int update(Team team);
	
	@Update("<script>" + "UPDATE teamtable\n" +
			  " <trim prefix=\"SET\" suffixOverrides=\",\">\n" + "<if test=\"userName!=null and userName!=''\">\n" +
			  " UserName=#{userName},\n" + "</if>\n" + "<if test=\"teamName!=null and teamName!=''\">\n" +
			  " TeamName=#{teamName},\n" + "</if>\n" + "<if test=\"currentNum!=null and currentNum!=''\">\n" +
			  " CurrentNum=#{currentNum},\n" + "</if>\n" + "<if test=\"maxNum!=null and maxNum!=''\">\n" +
			  " MaxNum=#{maxNum},\n" + "</if>" + "<if test=\"userEmail!=null and userEmail!=''\">\n" +
			  " UserEmail=#{userEmail},\n" + "</if>" + "<if test=\"teamEmail!=null and teamEmail!=''\">\n" +
			  " TeamEmail=#{teamEmail},\n" + "</if>" + "<if test=\"date!=null and date!=''\">\n" + 
			  " Date=#{date},\n" + "</if>" + "<if test=\"note!=null and note!=''\">\n" +
			  " Note=#{note},\n" + "</if>" + "<if test=\"dateTime!=null and dateTime!=''\">\n" +
			  " DateTime=#{dateTime},\n" + "</if>" + "<if test=\"teamState!=null and teamState!=''\">\n" +
			  " TeamState=#{teamState},\n" + "</if>" + " </trim>" + "WHERE TeamNo=#{teamNo}" + "</script>") 
	int update(Team team);

	
	/*
	 * @Update("<script>" + "UPDATE teamtable\n" +
	 * " <trim prefix=\"SET\" suffixOverrides=\",\">\n" +
	 * "<if test=\"userName!=null and userName!=''\">\n" +
	 * " UserName=#{userName},\n" + "</if>\n" +
	 * "<if test=\"password!=null and password!=''\">\n" +
	 * " Password=#{password},\n" + "</if>\n" +
	 * "<if test=\"teamName!=null and teamName!=''\">\n" +
	 * " TeamName=#{teamName},\n" + "</if>\n" +
	 * "<if test=\"category!=null and category!=''\">\n" +
	 * " Category=#{category},\n" + "</if>" +
	 * "<if test=\"discipline!=null and discipline!=''\">\n" +
	 * " Discipline=#{discipline},\n" + "</if>" +
	 * "<if test=\"currentNum!=null and currentNum!=''\">\n" +
	 * " CurrentNum=#{currentNum},\n" + "</if>" +
	 * "<if test=\"maxNum!=null and maxNum!=''\">\n" + " MaxNum=#{maxNum},\n" +
	 * "</if>" + "<if test=\"userEmail!=null and userEmail!=''\">\n" +
	 * " UserEmail=#{userEmail},\n" + "</if>" +
	 * "<if test=\"teamEmail!=null and teamEmail!=''\">\n" +
	 * " TeamEmail=#{teamEmail},\n" + "</if>" +
	 * "<if test=\"userRole!=null and userRole!=''\">\n" +
	 * " UserRole=#{userRole},\n" + "</if>" +
	 * "<if test=\"date!=null and date!=''\">\n" + " Date=#{date},\n" + "</if>" +
	 * "<if test=\"note!=null and note!=''\">\n" + " Note=#{note},\n" + "</if>" +
	 * "<if test=\"dateTime!=null and dateTime!=''\">\n" +
	 * " DateTime=#{dateTime},\n" + "</if>" +
	 * "<if test=\"ifuse!=null and ifuse!=''\">\n" + " IfUse=#{ifuse},\n" + "</if>"
	 * + "<if test=\"state!=null and state!=''\">\n" + " State=#{state}\n" + "</if>"
	 * + " </trim>" + "WHERE TeamNo=#{teamNo}" + "</script>") int update(BaseModel
	 * baseModel);
	 */
	 

	@Delete("<script>" + "delete from teamtable" + " WHERE TeamNo=#{teamNo}" + "</script>")
	int delete(BaseModel baseModel);

	@Select({ "select * from teamtable where TeamNo = #{teamNo}" })
	Team queryByTeamNo(String teamNo);


	int checkTeamState(String teamNo);

	@Select("SELECT * FROM teamtable WHERE TeamNo = #{teamNo}")
	Team selectTeamById(String teamNo);

	@Select("select * from teamtable where TeamEmail = #{teamEmail}")
	List<Team> selectTeamByEmail(String teamEmail);

}
